/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package processer;

import com.sun.corba.se.impl.orbutil.closure.Constant;
import main.BotManager;
import main.Constants;
import main.IGameDisplay;
import utils.Debug;

/**
 *
 * @author Administrator
 */
public abstract class Player extends Processer implements IGameDisplay {

    protected int playerId;
    protected int numberPlayers;
    protected int maxPlayer;
    private long startTime;
    protected boolean isFightCard;
    private long timeWait;
    private long[] timeList = {1000, 5000, 2000, 3000};
    protected int myViewId;
    protected boolean isViewer;
    protected int firtTurn;

    public Player(RoBot parent, GameData gameData, BotManager manager) {
        super(parent, gameData, manager);
        initValue();
    }

    private void initValue() {
        gameData.setGameDisplay(this);
        this.maxPlayer = gameData.getMaxPlayer();
        this.numberPlayers = gameData.getNumberPlayers();
        this.playerId = gameData.getPlayerId();
    }

    @Override
    public void doLoop() {
        if (startTime == 0) {
            startTime = System.currentTimeMillis();
        }
//        if (Debug.isTest) {
//            if (System.currentTimeMillis() - startTime > 2500) {
//                isFightCard = true;
//            }
//        } else {
//            if (System.currentTimeMillis() - startTime > timeWait / 2) {
//                isFightCard = true;
//            }
//        }

        if (gameData.getGameTypePlay() == Constants.BA_CAY) {
            int index = utils.Utils.nextInt(4);
            timeWait = timeList[index];
            if (System.currentTimeMillis() - startTime > timeWait) {
                isFightCard = true;

            }
        } else if (System.currentTimeMillis() - startTime > 5000) {
            isFightCard = true;
        }
        if (isFightCard) {

            startTime = System.currentTimeMillis();
            isFightCard = false;
            doFightCard();
        }
    }

    public void setTimeWait(long timeWait) {
        this.timeWait = timeWait;
    }

    abstract void doFightCard();
//------------------------------------------------------------------------------

    @Override
    public void setPlayerId(int id) {
        this.playerId = id;
    }

    @Override
    public void setNumberPlayer(int number) {
        this.numberPlayers = number;
    }

    @Override
    public void setTableHostId(int id) {
    }

    @Override
    public void setNumberPlayerReady(int number) {
    }

    @Override
    public void setMaxPlayer(int number) {
        this.maxPlayer = number;
    }

    @Override
    public void setGameRule(int gameRule) {
    }

    public void setFirstTurn(int turn) {
        firtTurn = turn;
    }

    @Override
    public void setMyViewId(int id) {
        myViewId = id;
        isViewer = (myViewId < maxPlayer ? false : true);
        if (isViewer) {
            playerId = 0;
        }
        Debug.d("set view id :" + myViewId + "," + isViewer);
    }
}
